package com.wxxymaker.edu.controller;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.annotation.Param;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.PathParam;
import com.blade.mvc.annotation.PostRoute;
import com.blade.mvc.ui.RestResponse;
import com.wxxymaker.edu.model.entity.ImageInfo;
import com.wxxymaker.edu.roles.AdminRoles;
import com.wxxymaker.edu.roles.IgnoreAuth;
import com.wxxymaker.edu.service.ImageInfoService;
import io.github.biezhi.anima.page.Page;

/**
 * @AUTHOR soft
 * @DATE 2018/10/18 19:08
 * @DESCRIBE
 */
@AdminRoles
@Path(value = "/admin/bigImage", restful = true)
public class ImageInfoHandler {

    @Inject
    private ImageInfoService imageInfoService;

    @IgnoreAuth
    @PostRoute("/page")
    public RestResponse page(@Param(defaultValue = "1") Integer type,
                             @Param(defaultValue = "1") Integer page,
                             @Param(defaultValue = "5") Integer size) {
        Page<ImageInfo> page1 = imageInfoService.page(type, page, size);
        if (page1 != null) {
            return RestResponse.ok(page1);
        }
        return RestResponse.fail();
    }

    @PostRoute("/save")
    public RestResponse save(ImageInfo imageInfo) {
        ImageInfo add = imageInfoService.add(imageInfo);
        if (add != null) {
            return RestResponse.ok(add);
        }
        return RestResponse.fail();
    }

    @PostRoute("/delete/:id")
    public RestResponse delete_(@PathParam Integer id) {
        ImageInfo delete = imageInfoService.delete(id);
        if (delete != null) {
            return RestResponse.ok(delete);
        }
        return RestResponse.fail();
    }
}
